<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath(); 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>"> 
<meta charset="UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">  
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="css/edittable.css"  ></link>  
<link rel="stylesheet" type="text/css" href="css/validate.css"  ></link>  
<script type="text/javascript"  src="js/jquery-1.8.0.js"></script>
<script >
var reg = /^[^\s]{2,15}$/;
$(function() {
	$("#cateName").blur(function() {
		if ($("#cateName").val() == "" || $.trim($("#cateName").val()).length == 0) {
			document.getElementById("cateName_msg").style.color = "#ff0000";
		    document.getElementById("cateName_msg").innerHTML = "分类不能为空!";
		}else if (reg.test($("#cateName").val()) === false) {
			document.getElementById("cateName_msg").style.color = "#ff0000";
		    document.getElementById("cateName_msg").innerHTML = "分类名不合格，请输入\"2-15位非空白字符\"";
		}else {
			document.getElementById("cateName_msg").style.color = "green";
		    document.getElementById("cateName_msg").innerHTML = "验证通过";
		}
	});
})
function validate() {
	if ($("#cateName").val() == "" || $.trim($("#cateName").val()).length == 0) {
		document.getElementById("cateName_msg").style.color = "#ff0000";
	    document.getElementById("cateName_msg").innerHTML = "分类不能为空!";
	    return false;
	}else if (reg.test($("#cateName").val()) === false) {
		document.getElementById("cateName_msg").style.color = "#ff0000";
	    document.getElementById("cateName_msg").innerHTML = "分类名不合格，请输入\"2-15位非空白字符\"";
	    return false;
	}else{
		result = confirm("确定要提交吗?");
        return result;
	}
}
$(function() {
	$("#submit").click(function () {
		if (validate()) {
			$.ajax({
				 url:"CateServlet.do",
				 type:"POST",
				 data:{flag:"bigcateUpdate",id:'${cate.id}',cateName:$("#cateName").val(),des:$("#des").val()},
				 success:function(data){
					 $("#result_msg").html(data);
				 } 
			 }); 
		}
		
	});
})
</script>
</head>
<body>
	<div class ="div_title">
			 <div class="div_titlename"> <img src="images/san_jiao.gif" ><span>商品管理&ensp;添加一级分类</span></div>
	</div>
	<form action="CateServlet.do" onsubmit="return validate()" method="post">
	<input type="hidden" name="flag" value="bigcateAdd">
		<table class="edit_table" >
		<tr>
 			 	<td class="td_info">分类名称:</td>	
 			 	<td class="td_input_short"> 
 			 		<input type="text" class="txtbox" id="cateName" name="cateName"  value="${cate.cateName }"/> 
 			 	</td>   
 			 	<td>
 			 		<label class="validate_info" id="cateName_msg">2-15位非空白字符</label>
 			 	</td> 
 		</tr>
 		<tr>
 			<td class="td_info">分类描述:</td>	
 			<td><textarea rows="4" cols="27" name="des" class="txtarea" id="des">${cate.des }</textarea> </td>	
 			<td><label></label></td>	
 		</tr>
 		<tr>
 			<td class="td_info"> </td>	
 			<td> 
	 			<input class="form_btn" type="button" value="修改" id="submit"/> 
	 			<input type="button" onclick="self.location=document.referrer;" class="form_btn" value="返回" />
 			</td>	
 			<td>
 				<label id="result_msg" class="result_msg">${msg}</label>
 			</td>	
 		</tr>
		</table>
	</form>
</body>
</html>